package com.btpn.infra.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;

import com.btpn.custody.common.Constant;

public class MyDateUtils {

	private static SimpleDateFormat format;
	
	/*
	 * java.util.Date --> String without exception
	 */
	public static String dateToStr(String pattern, java.util.Date date) {
		format = new SimpleDateFormat(pattern);
		
		try {
			return format.format(date);
		} catch (Exception e) {
			return "";
		}
	}
	
	/*
	 * String --> java.util.Date without exception
	 */
	public static java.util.Date strToDate(String pattern, String strDate) {
		format = new SimpleDateFormat(pattern);
		
		try {
			return format.parse(strDate);
		} catch (Exception e) {
			return null;
		}
	}
	
	public static String StringToStringFormatDate(String oldPattern, String newPattern, String strdate){
		 SimpleDateFormat df = new SimpleDateFormat(oldPattern);  
		 SimpleDateFormat newformat = new SimpleDateFormat(newPattern);
		 
		 try {
			String reformattedStr = newformat.format(df.parse(strdate));
			return reformattedStr;
		} catch (ParseException e) {
			return null;
		}
		
	}
}
